What is has-yarn?
The has-yarn npm package is a simple utility that checks if a project is using Yarn as its package manager by looking for a 'yarn.lock' file in the project directory. It is useful for tooling and scripts that need to adapt their behavior based on the package manager being used.
What are has-yarn's main functionalities?
Check if Yarn is being used
This feature allows you to check if a project is using Yarn by invoking the hasYarn function. It returns true if a 'yarn.lock' file is found in the project directory, indicating that Yarn is being used.
const hasYarn = require('has-yarn');
if (hasYarn()) {
console.log('The project uses Yarn.');
} else {
console.log('The project does not use Yarn.');
}
Other packages similar to has-yarn
yarn-or-npm
yarn-or-npm is a more versatile package that can detect whether Yarn or npm is being used in a project. It can return 'yarn' or 'npm' based on the lock file detected, providing a direct comparison to the singular focus of has-yarn.
has-yarn
Check if a project is using Yarn
Useful for tools that needs to know whether to use yarn
or npm
to install dependencies.
It checks if a yarn.lock
file is present in the working directory.
Install
$ npm install has-yarn
Usage
.
├── foo
│ └── package.json
└── bar
├── package.json
└── yarn.lock
const hasYarn = require('has-yarn');
hasYarn('foo');
hasYarn('bar');
API
hasYarn([cwd])
Returns a boolean
of whether the project uses Yarn.
cwd
Type: string
Default: process.cwd()
Current working directory.
Related
License
MIT © Sindre Sorhus